﻿using D.B.Data.Domain;
using D.B.Data.ErrorCode;
using D.B.Data.Infrastructuse;
using Microsoft.EntityFrameworkCore;

namespace D.B.Data.WebAPI.Applications
{
    public class Services : IServices
    {
        private readonly IBaseRepository<AccountModel> baseRepository;

        public Services(IBaseRepository<AccountModel> baseRepository)
        {
            this.baseRepository = baseRepository;
        }

        public APIResult<List<AccountModel>> GetAccount()
        {
            var res = baseRepository.GetAll().AsNoTracking().ToList();
            return new APIResult<List<AccountModel>>()
            {
                Code=200,
                Msg="显示成功",
                Data=res
            };
        }

        public APIResult<int> UpdateState(int Id,int State)
        {
            var res = baseRepository.GetAll().FirstOrDefault(s => s.Id == Id);
            APIResult<int> aPIResult = new APIResult<int>();
            if (State == 1)
            {
                res.State = 0;
                baseRepository.UpData(res);
                aPIResult.Code = 200;
                aPIResult.Data = 1;
                aPIResult.Msg = "启用成功";
                return aPIResult;
            }
            else
            {
                res.State = 1;
                baseRepository.UpData(res);
                aPIResult.Code = 200;
                aPIResult.Data = 1;
                aPIResult.Msg = "禁用成功";
                return aPIResult;
            }
                

          
          

         
        }
    }
}
